#include <stdio.h>
#include <stdlib.h>

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int find_first(int *nums,int left,int right,int target){
    int mid=left+((right-left)>>1);
    if( left > right )
        return left;
    if( nums[mid] >= target ){
        return find_first(nums,left,mid-1,target);
    }else{
        return find_first(nums,mid+1,right,target);
    }
}
int find_last(int *nums,int left,int right,int target){
    int mid=left+((right-left)>>1);
    if( left > right )
        return right;
    if( nums[mid] > target )
        return find_last(nums,left,mid-1,target);
    else
        return find_last(nums,mid+1,right,target);
}
int* searchRange(int* nums, int numsSize, int target, int* returnSize) {
    int f1=find_first(nums,0,numsSize-1,target);
    int f2=find_last(nums,0,numsSize-1,target);
    int *ret=malloc(sizeof(int)*2);
    *returnSize=2;
    if( f1 > f2 )
        ret[0]=ret[1]=-1;
    else{
        ret[0]=f1;
        ret[1]=f2;
    }
    return ret;
}

int main(){
    //int nums[]={5,7,7,8,8,10};
    int nums[]={};
    int rets;
    int *r=searchRange(nums,sizeof(nums)/sizeof(int),\
            6,&rets);
    printf("%d %d\n",r[0],r[1]);
    return 0;
}
